import java.util.LinkedList;

/**
 * 面试题09：用两个栈实现队列
 */
public class Offer_09 {
    public static void main(String[] args) {
        CQueue myQueue = new CQueue();
        System.out.println(myQueue.deleteHead());
        myQueue.appendTail(5);
        myQueue.appendTail(2);
        System.out.println(myQueue.deleteHead());
        System.out.println(myQueue.deleteHead());
    }
}

class CQueue {
    LinkedList<Integer> stackA, stackB;

    public CQueue() {
        stackA = new LinkedList<>();
        stackB = new LinkedList<>();
    }

    public void appendTail(int value) {
        stackA.push(value);
    }

    public int deleteHead() {
        if (stackB.isEmpty()) {
            while (!stackA.isEmpty()) {
                stackB.push(stackA.pop());
            }
        }
        if (!stackB.isEmpty()) {
            return stackB.pop();
        } else {
            return -1;
        }
    }
}

/**
 * Your CQueue object will be instantiated and called as such: CQueue obj = new
 * CQueue(); obj.appendTail(value); int param_2 = obj.deleteHead();
 */